package com.xkh.common.algorithm;

import org.junit.Test;

public class Algorithm {

    String arr1 = "([{";
    String arr2 = ")]}";

    @Test
    public void test11() {
        //()[]{}    ([)]    {[]}    ()[]{}  (]
        String s = "([)]";
        System.out.println(isValid(s));
    }

    public boolean isValid(String s) {
        int z = 0;
        int left = 0;
        int right = 0;
        for (int i = 0; i < s.length(); i++) {
            if (arr1.contains(String.valueOf(s.charAt(i)))) {
                left ++;
                z++;
            }else {
                right ++;
                if(s.charAt(i) !=  arr2.charAt(arr1.indexOf(s.charAt(i-z+1)))){
                    return false;
                }

            }
        }

        if(left != right){
            return false;
        }
        return true;
    }

    @Test
    public void test2(){
        String s = "([)]";
        System.out.println(arr1.indexOf("["));
    }


}
